package com.sinkingsquare.business.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sinkingsquare.business.BusinessService;
import com.sinkingsquare.dao.AccountDao;
import com.sinkingsquare.domain.Account;

@Service("businessService")
public class BusinessServiceImpl implements BusinessService {
	
	private AccountDao accountDao;

	public AccountDao getAccountDao() {
		return accountDao;
	}

	@Resource
	public void setAccountDao(AccountDao accountDao) {
		this.accountDao = accountDao;
	}

	public boolean accountExists(Account account) throws Exception {
		return accountDao.checkAccountExistsWithName(account.getUsername());
	}

	public void addAccount(Account account){
		accountDao.save(account);
	}

	public List<Account> getAllAccounts() {
		return accountDao.getAllAcounts();
	}

	public Account loadAccountById(int id) {
		return accountDao.loadAccountById(id);
	}

	public boolean accountLogin(String username, String password)
			throws Exception {
		return accountDao.checkAccountExistsWithNameAndPwd(username, password);
	}

}
